<template>
  <!-- 离职申请 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="searchValue.search"
            placeholder="姓名"
            clearable
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        row-key="id"
        stripe
        @row-dblclick="handleRowDblclick"
      >
        <el-table-column label="ID" prop="id" width="50"></el-table-column>
        <el-table-column
          label="部门"
          prop="departmentName"
          width="200"
        ></el-table-column>
        <el-table-column
          label="姓名"
          prop="adminName"
          width="200"
        ></el-table-column>
        <el-table-column label="离职日期" prop="departTime" width="250">
        </el-table-column>
        <el-table-column
          label="离职原因"
          prop="departReason"
          min-width="200"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          label="工作交接内容"
          prop="handoverWork"
          min-width="200"
          :show-overflow-tooltip="true"
        ></el-table-column>

        <el-table-column
          label="审核状态"
          prop="status"
          width="100"
          fixed="right"
        >
          <template #default="scope">
            <!-- 0未审核 1审核通过 2审核拒绝 3审核中  -->
            <p v-if="scope.row.status == 0">待审核</p>
            <p v-if="scope.row.status == 1" style="color: #67c23a">通过</p>
            <p v-if="scope.row.status == 2" style="color: #f56c6c">未通过</p>
            <p v-if="scope.row.status == 3" style="color: #ff9b31">审核中</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="right" width="250">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_show(scope.row, scope.$index)"
                >查看</el-button
              >
              <el-button
                text
                type="primary"
                size="small"
                @click="table_edit(scope.row, scope.$index)"
                v-if="scope.row.status == 0"
                >编辑</el-button
              >
              <el-popconfirm
                title="确定删除吗？"
                @confirm="table_del(scope.row, scope.$index)"
                v-if="scope.row.status == 0"
              >
                <template #reference>
                  <el-button text type="primary" size="small">删除</el-button>
                </template>
              </el-popconfirm>
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
</template>

<script>

export default {
  name: 'leaveApply',
  data () {
    return {
      apiObj: this.$API.leaveApply.getLeaveApplyList,
      userList: [],
      searchValue: {
        search: null,
      }
    }
  },

  methods: {

    //添加
    add () {
      this.$router.push({
        path: '/person/leaveApply/leaveApplyAdd',
        query: {
          mode: 'add'
        }
      })
    },
    //编辑
    table_edit (row) {
      this.$router.push({
        path: '/person/leaveApply/leaveApplyAdd',
        query: {
          mode: 'edit',
          id: row.id
        }
      })
    },
    //查看
    table_show (row) {
      this.$router.push({
        path: '/person/leaveApply/leaveApplyDetail',
        query: {
          id: row.id
        }
      })
    },
    //删除 
    async table_del (row) {
      var res = await this.$API.leaveApply.deletedLeaveApply.delete({ id: row.id })
      if (res.code == 200) {
        this.$refs.table.refresh()
        this.$message.success("删除成功")
      }
    },
    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },

    //本地更新数据
    handleSaveSuccess (data, mode) {

      this.$refs.table.refresh()
    },
    // 双击表格
    handleRowDblclick (row) {
      this.table_show(row)
    },
  }
}
</script>

<style>
</style>
